vc4_entrypoints = custom_target(
  'vc4_entrypoints.[ch]',
  input : ['vc4_entrypoints_gen.py', vk_api_xml],
  output : ['vc4_entrypoints.h', 'vc4_entrypoints.c'],
  command : [
    prog_python, '@INPUT0@', '--xml', '@INPUT1@', '--outdir',
    meson.current_build_dir()
  ],
  depend_files : files('vc4_extensions.py'),
)

vc4_extensions_c = custom_target(
  'vc4_extensions.c',
  input : ['vc4_extensions.py', vk_api_xml],
  output : ['vc4_extensions.c', 'vc4_extensions.h'],
  command : [
    prog_python, '@INPUT0@', '--xml', '@INPUT1@', '--out-c', '@OUTPUT0@',
    '--out-h', '@OUTPUT1@'
  ],
)

libvc4_files = files(
    'vc4_device.c',
    'vc4_util.c',
    'vc4_vk_formats.c',
    'vc4_vk_formats.h',
    'vc4_cmd_buffer.c',
    'vc4_memory.c',
    'vc4_memory.h',
    'vc4_wsi.c',
    'vc4_private.h',
    'vc4_vk_cl.c',
    'vc4_vk_cl.h',
    'vc4_vk_job.c',
    'vc4_vk_job.h',
    'vc4_pass.c',
    'vc4_image.c',
    'vc4_pipeline.c',
    'vc4_descriptor_set.c',
    'vc4_vk_fence.c',
    'vc4_vk_program.c',
    'vc4_vk_program.h',
    'vk_format_info.h',
    'vc4_pipeline_cache.c',
    'vc4_vk_queue.c',
    'vc4_copy.c',
)

qpu_files = files(
    'vc4_nir_lower_io.c',
    'vc4_nir_lower_txf_ms.c',
    'vc4_opt_algebraic.c',
    'vc4_opt_coalesce_ff_writes.c',
    'vc4_opt_constant_folding.c',
    'vc4_opt_copy_propagation.c',
    'vc4_opt_dead_code.c',
    'vc4_opt_peephole_sf.c',
    'vc4_opt_small_immediates.c',
    'vc4_opt_vpm.c',
    'vc4_qpu.c',
    'vc4_qpu.h',
    'vc4_qpu_defines.h',
    'vc4_qpu_disasm.c',
    'vc4_qpu_schedule.c',
    'vc4_qpu_validate.c',
    'vc4_qir.c',
    'vc4_qir_validate.c',
    'vc4_qir_emit_uniform_stream_resets.c',
    'vc4_qir_lower_uniforms.c',
    'vc4_qir_schedule.c',
    'vc4_reorder_uniforms.c',
    'vc4_tiling.h',
    'vc4_tiling_lt.c',
)

qpu_fixed_files = files(
    'vc4_qir.h',
    'vc4_qir_live_variables.c',
    'vc4_qpu_emit.c',
    'vc4_register_allocate.c',
    'vc4_nir_lower_blend.c',
    'vc4_uniforms.c',
    'vc4_emit.c',
    'vc4_tiling.c',
    'vc4_blit.c',
)

libvulkan_vc4_neon = []
if host_machine.cpu_family() == 'arm'
  libvulkan_vc4_neon = static_library(
    'vc4_neon',
    'vc4_tiling_lt_neon.c',
    include_directories : [
      inc_src, inc_include, inc_gallium, inc_gallium_aux, inc_broadcom
    ],
    c_args : '-mfpu=neon',
  )
  vc4_flags += '-DUSE_ARM_ASM'
endif

vc4_flags = []
# inc_vc4 = include_directories('../../gallium/drivers/vc4')

if system_has_kms_drm and not with_platform_android
  vc4_flags += '-DVK_USE_PLATFORM_DISPLAY_KHR'
  libvc4_files += files('vc4_wsi_display.c')
endif

libvulkan_vc4 = shared_library(
  'vulkan_vc4',
  [libvc4_files, qpu_files, qpu_fixed_files, vc4_entrypoints, vc4_extensions_c, v3d_xml_pack],
  include_directories : [
    inc_include,
    inc_src,
    inc_mapi,
    inc_mesa,
    inc_gallium,
    inc_gallium_aux,
    inc_compiler,
    inc_vulkan_wsi,
    inc_broadcom,
  ],
  link_with : [libbroadcom_cle, libbroadcom_v3d, libvulkan_wsi, libvulkan_vc4_neon],
  dependencies : [
    dep_dl,
    dep_elf,
    dep_libdrm,
    dep_m,
    dep_thread,
    dep_valgrind,
    idep_nir,
    idep_vulkan_util,
    idep_mesautil,
  ],
  c_args : [no_override_init_args, vc4_flags],
  gnu_symbol_visibility : 'hidden',
  link_args : [ld_args_bsymbolic, ld_args_gc_sections],
  install : true,
)

# vc4_test1=executable('vc4_test',
#   'vc4_nir_test.c',
#   include_directories: [ inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_compiler, inc_gallium_aux, inc_vulkan_wsi, inc_broadcom ],
#   dependencies : [dep_dl, dep_elf, dep_libdrm, dep_m, dep_thread, idep_nir, dep_valgrind, idep_vulkan_util, idep_mesautil],
# )

vc4_icd = custom_target(
  'vc4_icd',
  input : 'vc4_icd.py',
  output : 'vc4_icd.@0@.json'.format(host_machine.cpu()),
  command : [
    prog_python, '@INPUT@',
    '--lib-path', join_paths(get_option('prefix'), get_option('libdir')),
    '--out', '@OUTPUT@',
  ],
  depend_files : files('vc4_extensions.py'),
  build_by_default : true,
  install_dir : with_vulkan_icd_dir,
  install : true,
)
